﻿using System.Collections.Generic;

namespace RecipeModule
{
    public class RecipeDish
    {
        public int dishId;
        public int count;
    }
    
    public class Recipe
    {
        public int id;
        public string name;
        public int iconId;
        public RecipeType recipeType;
        public List<RecipeDish> listDish;
        public int useCount;

        public Recipe(int id)
        {
            this.id = id;
            iconId = 1;
            name = string.Empty;
            recipeType = RecipeType.Morning;
            listDish = new List<RecipeDish>();
            useCount = 0;
        }

        public Recipe Clone()
        {
            Recipe recipe = new Recipe(id);
            recipe.iconId = iconId;
            recipe.name = name;
            recipe.recipeType = recipeType;
            for (var i = 0; i < listDish.Count; i++)
            {
                RecipeDish dish = new RecipeDish();
                dish.dishId = listDish[i].dishId;
                dish.count = listDish[i].count;
                recipe.listDish.Add(dish);
            }
            recipe.useCount = useCount;
            return recipe;
        }

        public bool AddDish(Dish dish)
        {
            RecipeDish toFind = null;
            for (var i = 0; i < listDish.Count; i++)
            {
                if (listDish[i].dishId == dish.id)
                {
                    toFind = listDish[i];
                    break;
                }
            }

            if (toFind == null && listDish.Count < 8)
            {
                toFind = new RecipeDish();
                toFind.dishId = dish.id;
                toFind.count = 0;
                listDish.Add(toFind);
            }

            if (toFind != null)
            {
                ++toFind.count;
                return true;
            }

            return false;
        }
    }
}